package Model;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

public class Dryer {
	public String get7DData(String rawData) {

		rawData = rawData.replaceAll(" +", " ");
		String arrayData[] = rawData.split(" ");
		int intCount;
		Integer countNum = 1;
		String result = "";
		String washOrderCommand = "";

		// 童锁状态
		String childLockStatus = arrayData[12];
		String binaryString = Integer.toBinaryString(Integer.parseInt(childLockStatus, 16));
		while (binaryString.length() < 8) {
			binaryString = "0" + binaryString;
		}
		char childLockStatusbit0 = binaryString.charAt(0);
		switch (childLockStatusbit0) {
		case '0':
			washOrderCommand = "解锁";
			break;
		case '1':
			washOrderCommand = "锁定";
			break;

		default:
			break;
		}
		result = (countNum++) + ":" + washOrderCommand + "@";

		char childLockStatusbit1 = binaryString.charAt(1);
		switch (childLockStatusbit1) {
		case '0':
			washOrderCommand = "启动";
			break;
		case '1':
			washOrderCommand = "暂停";
			break;

		default:
			break;
		}
		result = (countNum++) + ":" + washOrderCommand + "@";

		char childLockStatusbit2 = binaryString.charAt(2);
		switch (childLockStatusbit2) {
		case '0':
			washOrderCommand = "关机";
			break;
		case '1':
			washOrderCommand = "开机";
			break;

		default:
			break;
		}
		result = (countNum++) + ":" + washOrderCommand + "@";

		// 预约时间
		String resnTime = arrayData[13] + arrayData[14];
		intCount = Integer.parseInt(resnTime, 16);
		float Time = (float) (intCount / 2.0);
		DecimalFormat fnum = new DecimalFormat("##0.00");
		String TimeStr = fnum.format(Time) + "h";
		washOrderCommand = "预约时间:" + TimeStr;
		result = (countNum++) + ":" + washOrderCommand + "@";

		// 剩余预约时间
		String remainingResnTime = arrayData[15] + arrayData[16];
		intCount = Integer.parseInt(remainingResnTime, 16);
		washOrderCommand = "剩余预约时间:" + intCount + "min";
		result = (countNum++) + ":" + washOrderCommand + "@";

		// 定时时间
		String dryTime = arrayData[17] + arrayData[18];
		intCount = Integer.parseInt(dryTime, 16);
		washOrderCommand = "定时时间:" + intCount + "min";
		result = (countNum++) + ":" + washOrderCommand + "@";

		// 剩余定时时间
		String remainingDryTime = arrayData[19] + arrayData[20];
		intCount = Integer.parseInt(remainingDryTime, 16);
		washOrderCommand = "剩余定时时间:" + intCount + "min";
		result = (countNum++) + ":" + washOrderCommand + "@";

		// 熨烫提醒功能状态,蜂鸣静音，除菌功能状态
		String ironRemainStatus = arrayData[22];
		binaryString = Integer.toBinaryString(Integer.parseInt(ironRemainStatus, 16));
		while (binaryString.length() < 8) {
			binaryString = "0" + binaryString;
		}
		char ironRemainStatusbit0 = binaryString.charAt(0);
		switch (ironRemainStatusbit0) {
		case '0':
			washOrderCommand = "呵护功能状态关";
			break;

		case '1':
			washOrderCommand = "呵护功能状态开";

		default:
			break;
		}
		result = (countNum++) + ":" + washOrderCommand + "@";

		char ironRemainStatusbit1 = binaryString.charAt(1);
		switch (ironRemainStatusbit1) {
		case '0':
			washOrderCommand = "除菌功能状态关";
			break;

		case '1':
			washOrderCommand = "除菌功能状态开";

		default:
			break;
		}
		result = (countNum++) + ":" + washOrderCommand + "@";
		char ironRemainStatusbit2 = binaryString.charAt(2);
		switch (ironRemainStatusbit2) {
		case '0':
			washOrderCommand = "蜂鸣器不静音关";
			break;

		case '1':
			washOrderCommand = "蜂鸣器静音";

		default:
			break;
		}
		result = (countNum++) + ":" + washOrderCommand + "@";

		char ironRemainStatusbit3 = binaryString.charAt(3);
		switch (ironRemainStatusbit3) {
		case '0':
			washOrderCommand = "无熨烫提醒";
			break;
		case '1':
			washOrderCommand = "有熨烫提醒";
		default:
			break;
		}
		result = (countNum++) + ":" + washOrderCommand + "@";

		// 防皱时间
		String antiCreaseTime = arrayData[23];
		intCount = Integer.parseInt(antiCreaseTime, 16);
		washOrderCommand = "防皱时间:" + intCount + "h";
		result = (countNum++) + ":" + washOrderCommand + "@";

		// 温度等级
		String tempLevel = arrayData[25];
		switch (tempLevel) {
		case "01":
			washOrderCommand = "冷风";
			break;
		case "02":
			washOrderCommand = "低温";
			break;
		case "03":
			washOrderCommand = "中温";
			break;
		case "04":
			washOrderCommand = "高温";
			break;
		default:
			break;
		}
		result = (countNum++) + ":" + washOrderCommand + "@";

		// 干燥程度
		String dryLevel = arrayData[26];
		switch (dryLevel) {
		case "01":
			washOrderCommand = "特底（即熨）";
			break;
		case "02":
			washOrderCommand = "较低（即穿）";
			break;
		case "03":
			washOrderCommand = "普通（储藏）";
			break;
		case "04":
			washOrderCommand = "较高（特干）";
			break;
		case "05":
			washOrderCommand = "特高";
			break;
		default:
			break;
		}
		result = (countNum++) + ":" + washOrderCommand + "@";

		// 干燥程序
		String dryCycle = arrayData[27];
		switch (dryCycle) {
		case "00":
			washOrderCommand = "空流程";
			break;
		case "01":
			washOrderCommand = "棉麻";
			break;
		case "02":
			washOrderCommand = "化纤";
			break;
		case "03":
			washOrderCommand = "混合/混纺";
			break;
		case "04":
			washOrderCommand = "毛巾";
			break;
		case "05":
			washOrderCommand = "家纺/床单/被罩";
			break;
		case "06":
			washOrderCommand = "衬衣";
			break;
		case "07":
			washOrderCommand = "内衣";
			break;
		case "08":
			washOrderCommand = "童装/婴儿装";
			break;
		case "09":
			washOrderCommand = "牛仔";
			break;
		case "0A":
			washOrderCommand = "窗帘";
			break;
		case "0B":
			washOrderCommand = "运动服";
			break;
		case "0C":
			washOrderCommand = "夜间烘";
			break;
		case "0D":
			washOrderCommand = "定时";
			break;
		case "0E":
			washOrderCommand = "羽绒";
			break;
		case "0F":
			washOrderCommand = "羊毛/羊毛-支架";
			break;
		case "10":
			washOrderCommand = "丝绸";
			break;
		case "11":
			washOrderCommand = "清新";
			break;
		case "12":
			washOrderCommand = "支架烘";
			break;
		case "13":
			washOrderCommand = "暖衣";
			break;
		case "14":
			washOrderCommand = "被子";
			break;
		case "15":
			washOrderCommand = "大件/大物";
			break;
		case "16":
			washOrderCommand = "浴巾";
			break;
		case "17":
			washOrderCommand = "快速20";
			break;
		case "18":
			washOrderCommand = "快速30";
			break;
		case "19":
			washOrderCommand = "工装";
			break;
		case "1A":
			washOrderCommand = "校服";
			break;
		case "1B":
			washOrderCommand = "尿布";
			break;
		case "1C":
			washOrderCommand = "鞋子";
			break;
		case "1D":
			washOrderCommand = "冲锋衣";
			break;
		case "1E":
			washOrderCommand = "羽绒服";
			break;
		case "1F":
			washOrderCommand = "超柔";
			break;
		case "20":
			washOrderCommand = "精细";
			break;
		case "21":
			washOrderCommand = "户外";
			break;
		case "22":
			washOrderCommand = "休闲装";
			break;
		case "23":
			washOrderCommand = "冷风30";
			break;
		case "24":
			washOrderCommand = "热风定时";
			break;
		case "25":
			washOrderCommand = "冷风定时";
			break;
		case "26":
			washOrderCommand = "快速";
			break;
		case "27":
			washOrderCommand = "除菌";
			break;
		case "28":
			washOrderCommand = "空气洗";
			break;
		default:
			break;
		}
		result = (countNum++) + ":" + washOrderCommand + "@";

		// 程序运行节点
		String cyclePhase = arrayData[28];
		switch (cyclePhase) {
		case "00":
			washOrderCommand = "待机状态";
			break;
		case "01":
			washOrderCommand = "预约运行";
			break;
		case "02":
			washOrderCommand = "冷风1";
			break;
		case "03":
			washOrderCommand = "加热1";
			break;
		case "04":
			washOrderCommand = "加热2";
			break;
		case "05":
			washOrderCommand = "冷风2";
			break;
		case "06":
			washOrderCommand = "程序结束";
			break;
		case "07":
			washOrderCommand = "防皱";
			break;
		default:
			break;
		}
		result = (countNum++) + ":" + washOrderCommand + "@";

		// 演示待机时间设定有无，强制删除
		String forceDelet = arrayData[29];
		binaryString = Integer.toBinaryString(Integer.parseInt(forceDelet, 16));
		while (binaryString.length() < 8) {
			binaryString = "0" + binaryString;
		}
		char forceDeletbit0 = binaryString.charAt(0);
		switch (forceDeletbit0) {
		case '0':
			washOrderCommand = "强制删除无";
		case '1':
			washOrderCommand = "强制删除有";
			break;
		default:
			break;
		}
		result = (countNum++) + ":" + washOrderCommand + "@";

		char forceDeletbit1 = binaryString.charAt(1);
		switch (forceDeletbit1) {
		case '0':
			washOrderCommand = "延时待机时间设定无";
		case '1':
			washOrderCommand = "延时待机时间设定有";
			break;
		default:
			break;
		}
		result = (countNum++) + ":" + washOrderCommand + "@";

		// 门开关状态,水位开关工作状态，照明灯工作状态，排水泵工作状态，风机工作状态，转筒工作状态，压机工作状态
		String doorSwitchStatus = arrayData[32];
		binaryString = Integer.toBinaryString(Integer.parseInt(doorSwitchStatus, 16));
		while (binaryString.length() < 8) {
			binaryString = "0" + binaryString;
		}
		char doorSwitchStatusbit0 = binaryString.charAt(0);
		switch (doorSwitchStatusbit0) {
		case '0':
			washOrderCommand = "压机工作状态停止";
			break;
		case '1':
			washOrderCommand = "压机工作状态运行";
			break;
		default:
			break;
		}
		result = (countNum++) + ":" + washOrderCommand + "@";

		char doorSwitchStatusbit1 = binaryString.charAt(1);
		switch (doorSwitchStatusbit1) {
		case '0':
			washOrderCommand = "转筒电机工作状态停止";
			break;
		case '1':
			washOrderCommand = "转筒电机工作状态运行";
			break;
		default:
			break;
		}
		result = (countNum++) + ":" + washOrderCommand + "@";

		char doorSwitchStatusbit2 = binaryString.charAt(2);
		switch (doorSwitchStatusbit2) {
		case '0':
			washOrderCommand = "风机工作状态停止";
			break;
		case '1':
			washOrderCommand = "风机工作状态运行";
			break;
		default:
			break;
		}
		result = (countNum++) + ":" + washOrderCommand + "@";

		char doorSwitchStatusbit3 = binaryString.charAt(1);
		switch (doorSwitchStatusbit3) {
		case '0':
			washOrderCommand = "排水泵工作状态停止";
			break;
		case '1':
			washOrderCommand = "排水泵工作状态运行";
			break;
		default:
			break;
		}
		result = (countNum++) + ":" + washOrderCommand + "@";

		char doorSwitchStatusbit4 = binaryString.charAt(2);
		switch (doorSwitchStatusbit4) {
		case '0':
			washOrderCommand = "照明灯工作状态停止";
			break;
		case '1':
			washOrderCommand = "照明灯工作状态运行";
			break;
		default:
			break;
		}
		result = (countNum++) + ":" + washOrderCommand + "@";

		char doorSwitchStatusbit5 = binaryString.charAt(1);
		switch (doorSwitchStatusbit5) {
		case '0':
			washOrderCommand = "水位开关工作状态未动作";
			break;
		case '1':
			washOrderCommand = "水位开关工作状态已经动作";
			break;
		default:
			break;
		}
		result = (countNum++) + ":" + washOrderCommand + "@";

		char doorSwitchStatusbit6 = binaryString.charAt(2);
		switch (doorSwitchStatusbit6) {
		case '0':
			washOrderCommand = "门关";
			break;
		case '1':
			washOrderCommand = "门开";
			break;
		default:
			break;
		}
		result = (countNum++) + ":" + washOrderCommand + "@";

		// 温度传感器1温度
		String tempSensor1Value = arrayData[33];
		intCount = Integer.parseInt(tempSensor1Value, 16);
		washOrderCommand = "温度传感器1温度:" + intCount + "℃";
		result = (countNum++) + ":" + washOrderCommand + "@";

		// 温度传感器2温度
		String tempSensor2Value = arrayData[34];
		intCount = Integer.parseInt(tempSensor2Value, 16);
		washOrderCommand = "温度传感器2温度:" + intCount + "℃";
		result = (countNum++) + ":" + washOrderCommand + "@";

		// 温度传感器3温度
		String tempSensor3Value = arrayData[35];
		intCount = Integer.parseInt(tempSensor3Value, 16);
		washOrderCommand = "温度传感器3温度:" + intCount + "℃";
		result = (countNum++) + ":" + washOrderCommand + "@";

		// 温度传感器4温度
		String tempSensor4Value = arrayData[36];
		intCount = Integer.parseInt(tempSensor4Value, 16);
		washOrderCommand = "温度传感器4温度:" + intCount + "℃";
		result = (countNum++) + ":" + washOrderCommand + "@";

		// 温度传感器数值
		String humiditySensorValue = arrayData[37] + arrayData[38];
		intCount = Integer.parseInt(humiditySensorValue, 16);
		washOrderCommand = "温度传感器数值：" + (intCount + 80);
		result = (countNum++) + ":" + washOrderCommand + "@";

		// 累计工作周期
		String totalDryCycle = arrayData[39] + arrayData[40] + arrayData[41] + arrayData[42];
		long intCount1 = Long.parseLong(totalDryCycle, 16);
		washOrderCommand = "累计工作周期：" + intCount1;
		result = (countNum++) + ":" + washOrderCommand + "@";

		// 本次用电量
		String currentElectricityUsed = arrayData[43] + arrayData[44];
		intCount = Integer.parseInt(currentElectricityUsed, 16);
		washOrderCommand = "本次用电量：" + fnum.format((float) (intCount / 100.0)) + "kwh";
		result = (countNum++) + ":" + washOrderCommand + "@";

		// 累计用电量
		String totalElectricityUsed = arrayData[45] + arrayData[46] + arrayData[47] + arrayData[48];
		intCount1 = Long.parseLong(totalElectricityUsed, 16);
		washOrderCommand = "累计用电量：" + fnum.format((float) (intCount1 / 100.0)) + "kwh";
		result = (countNum++) + ":" + washOrderCommand + "@";

		// 电机工作总时长
		String motorTotalRunTime = arrayData[49] + arrayData[50] + arrayData[51] + arrayData[52];
		intCount1 = Long.parseLong(motorTotalRunTime, 16);
		washOrderCommand = "电机工作总时长：" + intCount1 + "min";
		result = (countNum++) + ":" + washOrderCommand + "@";

		// 加热器（压缩机）工作总时长
		String heaterTotalRunTime = arrayData[53] + arrayData[54] + arrayData[55] + arrayData[56];
		intCount1 = Long.parseLong(heaterTotalRunTime, 16);
		washOrderCommand = "加热器（压缩机）工作总时长：" + intCount1 + "min";
		result = (countNum++) + ":" + washOrderCommand + "@";

		// 延时关机时间
		String standbyTime = arrayData[57] + arrayData[58];
		intCount = Integer.parseInt(standbyTime, 16);
		washOrderCommand = "延时关机时间：" + intCount + "min";
		result = (countNum++) + ":" + washOrderCommand + "@";

		// 剩余延时关机时间
		String remainingStandbyTime = arrayData[59] + arrayData[60];
		intCount = Integer.parseInt(remainingStandbyTime, 16);
		washOrderCommand = "剩余延时关机时间：" + intCount + "min";
		result = (countNum++) + ":" + washOrderCommand + "@";

		// 提示信息
		String message = arrayData[61];
		switch (message) {
		case "00":
			washOrderCommand = "无提示信息";
			break;
		case "01":
			washOrderCommand = "熨烫提醒";
			break;
		case "02":
			washOrderCommand = "衣服已烘干";
			break;
		case "03":
			washOrderCommand = "请清理过滤器";
			break;
		case "04":
			washOrderCommand = "请清理水盒";
			break;
		case "05":
			washOrderCommand = "预留提示1";
			break;
		case "06":
			washOrderCommand = "预留提示2";
			break;
		default:
			break;
		}
		result = (countNum++) + ":" + washOrderCommand + "@";

		// 剩余防皱时间
		String remainingAntiCreaseTime = arrayData[63] + arrayData[64];
		intCount = Integer.parseInt(remainingAntiCreaseTime, 16);
		washOrderCommand = "剩余防皱时间：" + intCount + "min";
		result = (countNum++) + ":" + washOrderCommand;

		return result;
	}

	public String getAlarm(String rawData) {
		rawData = rawData.replaceAll(" +", " ");
		String arrayData[] = rawData.split(" ");
		String message = arrayData[12] + arrayData[13];
		System.out.println(message);
		String binaryStr = "";
		String alarmSignificant = "";
		for (int i = 0; i < message.length(); i++) {
			String s = Integer.toBinaryString(Integer.parseInt(String.valueOf(message.charAt(i)), 16));
			// 拼接串 拼成4位
			while (s.length() < 4) {
				s = "0" + s;
			}
			binaryStr += s;
		}
		System.out.println("输出二进制:" + binaryStr);
		List<Integer> addr = new ArrayList<Integer>();
		if (binaryStr.contains("1")) {
			for (int j = 0; j < binaryStr.length(); j++) {
				if (String.valueOf(binaryStr.charAt(j)).equals("1")) {
					addr.add(j);
				}
			}
		} else {
			addr.add(16);
		}
		/***
		 *
		 * 重新定判定报警信息: bianaryStr为0 则解除报警,固定j=16为告警解除
		 * 在bianaryStr中第15位出现为:排水泵（水位开关）故障（F2） 在bianaryStr中第14位出现为:NTC1故障（F31）
		 * 在bianaryStr中第13位出现为:NTC2故障（F32） 在bianaryStr中第12位出现为:加热异常（制冷剂泄漏）（F4）
		 * 在bianaryStr中第11位出现为:过滤网堵塞（E6） 在bianaryStr中第10位出现为:电机故障（电机驱动板）（E7）
		 * 在bianaryStr中第9位出现为:电机故障（电机过热）（E8） 在bianaryStr中第8位出现为:NTC2温度低于2度（L0）
		 * 在bianaryStr中第7位出现为:与电源板（显示板）通讯故障（F5）
		 * 在bianaryStr中第6位出现为:与电机控制板通讯故障（E9） 在bianaryStr中第5位出现为:开门报警（dr）
		 * 在bianaryStr中第4位出现为:集水盒满报警（H20FULL） 在bianaryStr中第3位出现为:机器暂停报警
		 * 在bianaryStr中第2位出现为:NTC3故障（F33）
		 */

		for (int k = 0; k < addr.size(); k++) {
			switch (addr.get(k)) {
			case 16:
				alarmSignificant += "告警解除";
				alarmSignificant += "@/";
				break;
			case 15:
				alarmSignificant += "排水泵（水位开关）故障";
				alarmSignificant += "@F2,";
				break;
			case 14:
				alarmSignificant += "NTC1故障";
				alarmSignificant += "@F31,";
				break;
			case 13:
				alarmSignificant += "NTC2故障";
				alarmSignificant += "@F32,";
				break;
			case 12:
				alarmSignificant += "加热异常（制冷剂泄漏）";
				alarmSignificant += "@F4,";
				break;
			case 11:
				alarmSignificant += "过滤网堵塞";
				alarmSignificant += "@E6,";
				break;
			case 10:
				alarmSignificant += "电机故障（电机驱动板）";
				alarmSignificant += "@E7,";
				break;
			case 9:
				alarmSignificant += "电机故障（电机过热）";
				alarmSignificant += "@E8,";
				break;
			case 8:
				alarmSignificant += "NTC2温度低于2度";
				alarmSignificant += "@L0,";
				break;
			case 7:
				alarmSignificant += "与电源板（显示板）通讯故障";
				alarmSignificant += "@F5,";
				break;
			case 6:
				alarmSignificant += "与电机控制板通讯故障";
				alarmSignificant += "@E9,";
				break;
			case 5:
				alarmSignificant += "开门报警";
				alarmSignificant += "@dr,";
				break;
			case 4:
				alarmSignificant += "集水盒满报警";
				alarmSignificant += "@H20FULL,";
				break;
			case 3:
				alarmSignificant += "机器暂停报警";
				alarmSignificant += "@unkown,";
				break;
			case 2:
				alarmSignificant += "NTC3故障";
				alarmSignificant += "@F33,";
				break;
			}
		}

		return alarmSignificant;

	}

	public static void main(String[] args) {
		String alarm1 = "FF FF 16 00 00 00 00 00 00 04 0F 5A 00 00 84";
		String test_7Dorder = "FF FF 30 00 00 00 00 00 00 06 7D 01 03 00 00 00 00 00 00 14 00 14 00 00 00 00 02 03 01 05 04 00 00 08 00 02 01 00 01 16 17 00 EF 09 00 6B 38 E0 00 05 A7 ";
		// Dryer.get7DData(test_7Dorder);
	}

}
